proc deop {nick chan host otbn1 botnet handle} {

  global botnick home bcast

  # Cannot do anything if the bot is no op'd
  if {![botisop $chan]} {
    putquick "NOTICE $nick :\0034ERROR - Bot dosen't have op status (+o) on \002$chan"
    return 0
  }

  # if the user is deopping themselves...
  if {$otbn1 == "$nick"} {

    # if user is already deop'd...
    if {![isop $nick $chan]} {
      putquick "NOTICE $nick :\0034ERROR - You are currently not op'd on \002$chan"
      return 0
    }

    putlog "!$nick ($host)! deop $chan $nick"
    putquick "MODE $chan -o $nick"
    putquick "NOTICE $nick :\0033Sucessfully Deop'd\0034 $nick \0033on\0034 $chan"

    if {$bcast == "1"} {
      putquick "PRIVMSG $home :Deop'd \002$nick\002 ($host) In $chan"
    }

    return 0
  }

  # if noone is specified, assume user is talking about themselves
  # if there is no one with the nickname "me" - allow use of the "me" keyword from StormTCL
  if {($otbn1 == "") || ( ![onchan me $chan] && [string tolower $otbn1] == "me" ) } { 
    set otbn1 $nick

    # if user is not op'd
    if {![isop $nick $chan]} {
      putquick "NOTICE $nick :\0034ERROR You are currently not op'd on $chan"
      return 0
    } 

    putlog "!$nick ($host)! deop $chan $nick"
    putquick "MODE $chan -o $nick"
    putquick "NOTICE $nick :Sucessfully Deop'd $nick on $chan"

    if {$bcast == "1"} {
      putquick "PRIVMSG $home :Deop'd \002$nick\002 ($host) In $chan"
    }

    return 0
  }

  if {![isop $botnet $chan]} {
    putquick "NOTICE $nick :\0034ERROR - $botnet is currently not op'd on $chan"
    return 0
  } else {
    if {[onchan $botnet $chan]} {
      set hand2 [nick2hand $botnet $chan]

      # Block deoping of other bots on the botnet
      if {[string tolower $botnet] == [string tolower $botnick]} {
        putquick "NOTICE $nick :\0034ERROR - Unable To Deop other Bots on this Botnet."
        return 0
      }

      # if the user has lower acess than the user issuing the command, allow deop otherwise note insufficient permissions
      if {[checkaccess $handle $chan $hand2]} {
        putlog "!$nick ($host)! deop $chan $botnet"
        pushmode $chan -o $botnet
        putquick "NOTICE $nick :\0033Sucessfully deop'd \0034$botnet\0033 on \0034$chan"

        if {$bcast == "1"} {
          putquick "PRIVMSG $home :Deop'd \002$botnet\002 in $chan.(Requested by: \002$nick\002 ($host))"
        }
      } else {
        putquick "NOTICE $nick :\0034Unable To Execute Command - Permission Denied"

        if {$bcast == "1"} {
          putquick "PRIVMSG $home :\002$nick\002 ($host) tried to make me deop $botnet on $chan but they are a higher level."    
        }

        return 0
      }
    }
  }
}

